import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.script.InputManager;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;
import com.speljohan.rsbot.script.wrappers.RSTile;
import java.util.Map;

public class SoulDrizzt extends Script
{

    public RSTile AtPortalTile;
    public RSTile PortalTile;
    public RSTile BlueWait;
    public RSTile RedWait;
    public RSTile RedInside;
    public RSTile RedInside2;
    public RSTile RedInside3;
    public RSTile RedBarrier;
    public RSTile BlueInside;
    public RSTile BlueInside2;
    public RSTile BlueInside3;
    public RSTile BlueBarrier;
    int tries;

    public SoulDrizzt()
    {
        AtPortalTile = new RSTile(1890, 3164);
        PortalTile = new RSTile(1890, 3162);
        BlueWait = new RSTile(1875, 3162);
        RedWait = new RSTile(1904, 3162);
        RedInside = new RSTile(1954, 3239);
        RedInside2 = new RSTile(1954, 3244);
        RedInside3 = new RSTile(1954, 3234);
        RedBarrier = new RSTile(1959, 3239);
        BlueInside = new RSTile(1820, 3225);
        BlueInside2 = new RSTile(1820, 3230);
        BlueInside3 = new RSTile(1820, 3220);
        BlueBarrier = new RSTile(1815, 3225);
        tries = 0;
    }

    public String getAuthor()
    {
        return "Drizzt1112";
    }

    public String getName()
    {
        return "SoulDrizzt";
    }

    public double getVersion()
    {
        return 1.2D;
    }

    public String getScriptCategory()
    {
        return "Drizzt1112";
    }

    public String getScriptDescription()
    {
        String s = "<html>";
        s = (new StringBuilder()).append(s).append("<body>").toString();
        s = (new StringBuilder()).append(s).append("Description").toString();
        s = (new StringBuilder()).append(s).append("</body>").toString();
        s = (new StringBuilder()).append(s).append("</html>").toString();
        return s;
    }

    public boolean onStart(Map map)
    {
        return true;
    }

    public void onFinish()
    {
    }

    public int loop()
    {
        if(distanceTo(RedInside) < 5 || distanceTo(RedInside2) < 5 || distanceTo(RedInside3) < 5)
        {
            char c = '(';
            Bot.getInputManager().pressKey(c);
            wait(random(1500, 2000));
            Bot.getInputManager().releaseKey(c);
            wait(random(200, 500));
            turnToTile(RedBarrier);
            wait(random(200, 500));
            atTile(RedBarrier, "Pass Red barrier");
            wait(random(500, 800));
            return random(500, 750);
        }
        if(distanceTo(BlueInside) < 5 || distanceTo(BlueInside2) < 5 || distanceTo(BlueInside3) < 5)
        {
            char c1 = '(';
            Bot.getInputManager().pressKey(c1);
            wait(random(1500, 2000));
            Bot.getInputManager().releaseKey(c1);
            wait(random(200, 500));
            turnToTile(BlueBarrier);
            wait(random(200, 500));
            atTile(BlueBarrier, "Pass Blue barrier");
            wait(random(500, 800));
            return random(500, 750);
        }
        if(distanceTo(new RSTile(1959, 3239)) < 1)
        {
            walkTileMM(new RSTile(1967, 3239));
            return random(500, 750);
        }
        if(distanceTo(new RSTile(1967, 3239)) < 8 && walkTileMM(new RSTile(1960 + random(0, 14), 3232 + random(0, 12))))
        {
            log("Walked to a random tile");
            wait(random(60000, 0x2bf20));
            return random(500, 750);
        }
        RSInterface rsinterface = RSInterface.getInterface(211);
        if(rsinterface.isValid())
        {
            atInterface(211, 3);
            wait(random(500, 800));
            return random(500, 750);
        }
        RSInterface rsinterface1 = RSInterface.getInterface(228);
        if(rsinterface1.isValid())
        {
            atInterface(228, 2);
            wait(random(500, 800));
            return random(500, 750);
        }
        if(distanceTo(BlueWait) < 5 || distanceTo(RedWait) < 5)
        {
            tries = 0;
            wait(random(500, 800));
            return random(500, 750);
        }
        if(distanceTo(AtPortalTile) < 5)
        {
            tries++;
            log((new StringBuilder()).append("Tries: ").append(tries).toString());
            if(tries > 5)
            {
                log("Ewww, tried 5 times. Waiting now...");
                wait(random(60000, 0x2bf20));
                tries = 0;
            }
            atTile(PortalTile, "oin-");
            wait(random(500, 800));
            return random(500, 750);
        }
        if(distanceTo(AtPortalTile) < 18)
        {
            walkTileMM(AtPortalTile);
            wait(random(500, 800));
            return random(500, 750);
        } else
        {
            return random(100, 150);
        }
    }
}
